package com.briup.server.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.briup.common.response.Result;
import com.briup.server.domain.dto.DeviceModifiedDTO;
import com.briup.server.domain.dto.DeviceQueryDTO;
import com.briup.server.domain.vo.DeviceDetailVO;
import com.briup.server.service.DeviceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "设备相关接口")
@RestController
@RequestMapping("/device")
@RequiredArgsConstructor
public class DeviceController {

    private final DeviceService service;

    @Operation(summary = "按照条件查询设备信息（分页返回）")
    @GetMapping("/page")
    public Result<Page<DeviceDetailVO>> queryDevices(DeviceQueryDTO queryDTO) {
        Page<DeviceDetailVO> page = service.queryDevices(queryDTO);
        return Result.success(page)
                .apply("查询成功");
    }

    @Operation(summary = "新增设备")
    @PostMapping
    public Result<?> addDevice(@RequestBody DeviceModifiedDTO addDTO) {
        service.saveOrUpdateDevice(addDTO);
        return Result.success();
    }

    @Operation(summary = "更新设备信息")
    @PutMapping
    public Result<?> updateDevice(@RequestBody DeviceModifiedDTO updateDTO) {
        service.saveOrUpdateDevice(updateDTO);
        return Result.success();
    }

    @Operation(summary = "删除设备")
    @DeleteMapping
    public Result<?> deleteDevice(@RequestBody List<String> ids) {
        service.removeByIds(ids);
        return Result.success();
    }
}
